package com.google.project.server;

import java.util.Date;

import javax.jdo.PersistenceManager;

import com.google.project.server.entity.Users;

public class AppMisc {
	private static final String[] userCode = new String[] { "mg1", "mg2",
			"mg3", "mg4" };
	private static final String[] userName = new String[] { "admin", "sonnm",
		"ducnm", "khiemnt" };
	private static final String[] password = new String[] { "123456", "123456",
		"123456", "123456" };
	private static final String[] fullName = new String[] { "Admin", "Nguyễn minh sơn",
		"Nguyễn minh đức", "Nguyễn tiến khiêm" };
	private static final String[] birthday = new String[] { "1990/02/02", "03/03/1982",
		"04/04/1985", "05/05/1970" };
	private static final String[] status = new String[] { "2", "2",
		"2", "2" };
	private static final String[] userGroup = new String[] { "6", "4",
		"2", "1" };
	private static final String[] email = new String[] { "admin@tls.com.vn", "sonnm@tls.com.vn",
		"ducnm@tls.com.vn", "khiemnt@tls.com.vn" };
	
	@SuppressWarnings("deprecation")
	static void populateDataStoreOnce() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Users defaultUser = Users.getDefaultUser(pm);
	    if (defaultUser != null)
	      return; // already populated
		try {
			
			for(int i=0;i<userCode.length;i++){
				Users user=new Users();
				 user.setDefaulUser(userCode[i], userName[i],password[i], fullName[i], new Date(birthday[i]).getTime(), status[i], Long.parseLong(userGroup[i]),email[i]);
				pm.makePersistent(user);
			}	
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			pm.close();
		}
	}

}